﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Asteriods
{
    class GameObject
    {
        private Vector2 position = Vector2.Zero;
        public Vector2 Position
        {
            get { return position; }
        }
        private Vector2 velocity = Vector2.Zero;
        public Vector2 Velocity
        {
            get { return velocity; }
            set { velocity = value; }
        }
        private float rotation = 0f;
        public float Rotation
        {
            get { return rotation; }
            set { rotation = value; }
        }
        private Texture2D Image;
        private float scale = 1.0f;
        public GameObject(Game game, string imagepath)
        {
            Image = game.Content.Load<Texture2D>(imagepath);
        }

        public virtual Rectangle returnHitBox()
        {
            return new Rectangle((int)position.X, (int)position.Y, (int)((float)Image.Width * scale), (int)((float)Image.Height * scale));
        }

        public virtual void SetNewPositonVelocityandRotation(Vector2 newposition, Vector2 newvelocity, float newrotation)
        {
            position = newposition - new Vector2(Image.Width / 2, Image.Height / 2);
            velocity = newvelocity;
            rotation = newrotation;
        }

        public virtual void SetNewScale(float newscale)
        {
            this.scale = newscale;
        }

        public virtual void Update(GameTime gameTime, GraphicsDevice graphicsDevice)
        {
            position += velocity;
            if (position.X < -Image.Width)
                position.X = graphicsDevice.Viewport.Width + Image.Width;
            if (position.X > graphicsDevice.Viewport.Width + Image.Width)
                position.X = -Image.Width;
            if (position.Y < -Image.Height)
                position.Y = graphicsDevice.Viewport.Height + Image.Height;
            if (position.Y > graphicsDevice.Viewport.Height + Image.Height)
                position.Y = -Image.Height;
        }

        public virtual void Draw(GameTime gameTime, SpriteBatch spbatch)
        {
            spbatch.Draw(Image, position, null, Color.White, rotation, new Vector2(Image.Width / 2, Image.Height / 2), scale, SpriteEffects.None, 0);
        }

    }
}
